<template>
	<view class="container">
		<cu-custom  :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">
				意见反馈
			</block>
		</cu-custom>
		
		<view class="page-form">
			<u-form :model="formData" ref="uForm" :border-bottom="false" :label-style="{fontSize:'28rpx'}">

				<u-form-item label-width="140" label="事件类型" prop="category_id" required>
					<uni-data-picker :localdata="typeOptions"  class="text-cut" style="width: 200rpx;overflow: hidden;font-size:28rpx;" ref="typePicker" v-model="formData.category_id" popup-title="请选择事件类型" :border="false" placeholder="" :map="typeMap" @change="typeChange">
					
					</uni-data-picker>
				</u-form-item>

				<u-form-item label="反馈内容" label-position="top" prop="content">
					<u-input v-model="formData.content" placeholder="请填写反馈内容" type="textarea"></u-input>
				</u-form-item>

				<u-button @click="$stopClicks.noMultipleClicks(submitForm)" type="primary"
					style="margin-top: 35px;">提交</u-button>
			</u-form>
			<u-top-tips ref="uTips"></u-top-tips>
		</view>
		
		<u-toast ref="uToast" />
	</view>
</template>
<script>
	import {
		getFacebookCategoryData,
		saveFacebook
	} from "@/api/index.js"

	import request from "@/common/request.js";
	
	import {
		mapState,
		mapGetters
	} from "vuex";

	export default {

		data() {
			return {
				formData: {
					// gridId: "",
					content: "",
					category_id: "",
					seat_id: "",
					// attachId: [],
					// handlingImg:[],
				},
				uploadHeader: {},
				imgList: [],
				uploadFormData: {},
				
				typeOptions:[],
				typeMap: {
					text: 'title',
					value: 'id'
				},

				rules: {
					category_id: [{
						required: true,
						message: '请选择事件类型11',
						// trigger: ['change', 'blur'],
					}],
					// handlingImg: [{
					// 	validator: (rule, value, callback) => {
					// 		console.log(this.formData.attachId);
					// 		if (!this.formData.attachId || this.formData.attachId.length < 1) {
					// 			return callback(new Error("请输入上传反馈图片"))
					// 		}
					// 		return callback();
					// 	},
					// 	message: '请输入上传反馈图片',
					// 	trigger: ['change', 'blur'],
					// }],
				},

			}
		},
		computed: {
			...mapGetters(["userInfo"]),
		},
		onLoad(option) {
			//获取类型
			this.getTypeOptions();

		},
		onShow() {
			console.log("changepasswrod onshow");
		},
		methods: {
			//获取意见反馈类型
			getTypeOptions() {
				getFacebookCategoryData().then((res) => {
					let {data} = res;
					
					console.log("getFacebookCategoryData ",data);
					
					if (data.code == 200) {
						this.typeOptions = data.data
					}
				})
			},
			typeChange(data) {
				console.log("typeChange data",data);
				if (data.detail.value.length >= 1) {
					let info = data.detail.value;
					this.formData.category_id = info[0].value;
				}
			},
			submitForm() {
				let that = this;
				this.$refs.uForm.validate(valid => {
					console.log("form",valid,this.formData);
					if (valid) {
						let userinfo = uni.getStorageSync("userInfo");
						this.formData.seat_id = userinfo.id;
						
						saveFacebook(this.formData).then((res) => {
							let {data} = res;
							
							if (data.code == 200) {
								that.$store.dispatch("setPageCur",'me');
								
								that.$refs.uToast.show({
									title: data.msg,
									duration: 3000,
									message:data.msg,
									url:"/pages/index/tabbar"
								})
							} else {
								that.$refs.uToast.show({
									title: data.msg,
									message:data.msg,
									icon: 'error'
								});
							}
						})
					}
				})
			},

			async beforeUpload(index, list) {
				this.uploadHeader['Smart-Auth'] = this.$store.getters.smartAuth,
					this.uploadFormData = {
						joinId: this.data.id,
						joinName: 'smart_grid_admin_event_resolve',
						attachType: 1
					};
			},

			onSuccess(successData) {
				if (successData.code == 200) {
					this.formData.attachId.push(successData.data.attachId)
				}
			},
			imgRemove(index, lists) {
				let attachIds = [];
				lists.map((item) => {
					if (item.response && item.response.success) {
						attachIds.push(item.response.data.attachId)
					}
				})
				this.formData.attachId = attachIds

			},

		},

		onReady() {
			this.$refs.uForm.setRules(this.rules);
		}
	}
</script>
<style>
.container {
	width: 100%;
	color: #333333;
	background-image: linear-gradient(to bottom, #075AFF, #ffffff);
	background-size: 100% 45%;
	background-repeat: no-repeat;
	background-position: top center;
	overflow-y: scroll;
}
</style>